package com.sunny.l71;

/**
 * Given a set of distinct integers, S, return all possible subsets.
 */

import java.util.ArrayList;

/**
 * @Author zsunny
 * @Date 2018/9/22 20:30
 * @Mail zsunny@yeah.net
 */
public class Solution {
    ArrayList<ArrayList<Integer>> res = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> subsets(int[] S) {
        if(null == S || S.length == 0)
            return res;
        ArrayList<Integer> tmp = new ArrayList<>();
        dfs(S, tmp, 0);
        return res;
    }
    public void dfs(int[] arr, ArrayList<Integer> list, int ind){
        if(ind == arr.length){
            res.add(list);
            return;
        }
        ArrayList<Integer> list1 = new ArrayList<>(list);
        dfs(arr, list1, ind+1);
        ArrayList<Integer> list2 = new ArrayList<>(list);
        list2.add(arr[ind]);
        dfs(arr, list2, ind+1);
    }
}
